package day3;

import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class Map2 {
    public static void main(String[] args) {
        Map map=new HashMap();
        map.put("dog","狗");
        map.put("horse","马");
        map.put("ma","马");
        map.put("pig","猪");
        map.put("dog","老母狗");
        map.put("empty",null);
        Set s = map.keySet();
        System.out.println("所有的key:"+s);
        Collection values = map.values();
        System.out.println("所有的value："+values);
        System.out.println(">>>>>>>>>>>1:iter 循环key>>>>>>>>>>>>>>");
        Iterator ir = s.iterator();
        while (ir.hasNext()){
            Object key=ir.next();
            Object value=map.get(key);
            System.out.println(key+"="+value);
        }
        System.out.println(">>>>>>>>>>>for 循环key>>>>>>>>>>>>>>");
        for(Object key:s){
            Object value=map.get(key);
            System.out.println(key+"="+value);
        }
        System.out.println(">>>>>>>>>3:循环Map自己的迭代器>>>>>>>>>>>>>>");
        Set set = map.entrySet();
        for(Object o:set){
            Map.Entry en= (Map.Entry) o;

            System.out.println(en.getKey()+"="+en.getValue());
        }
        System.out.println(">>>>>>>>>>>>根据汉字找洋文>>>>>>>>>>>>>>>>>>>>>>>>>");
        String zhongwen="马";
        for(Object o:set){
            Map.Entry en= (Map.Entry) o;
            if(zhongwen.equals(en.getValue())){
                System.out.println(en.getKey());
            }
        }
    }
}
